import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
interface IntegerStack {
	public Integer pop();                
	public Integer push(Integer item);    
	public Integer peek();                  
	public boolean empty();                
	public int size();                            
}
class ArrayListIntegerStack implements IntegerStack {
	private List<Integer> arrList=new ArrayList<Integer>();
	@Override
	public Integer push(Integer item) {
	
		if(item==null)
		return null;
		arrList.add(item);
		return item;
	}

	@Override
	public Integer pop() {
	    if(arrList.size()==0)
	    	return null;
		return arrList.remove(arrList.size()-1);
	}

	@Override
	public Integer peek() {
	    if(arrList.size()==0)
		return null;
	    return arrList.get(arrList.size()-1);
	}

	@Override
	public boolean empty() {
       return arrList.size()==0?true:false;
		
	}

	@Override
	public int size() {
	   return arrList.size();
	}


	@Override
	public String toString() {
		return arrList.toString();
	
	}
}
public class Main {

	public static void main(String[] args) {
	    ArrayListIntegerStack arr = new ArrayListIntegerStack();
        Scanner in=new Scanner(System.in);
        int m=in.nextInt();
        for(int i=0;i<m;i++)
        { 
        	System.out.println( arr.push(in.nextInt()));
        }
          System.out.println( arr.peek()+","+arr.empty()+","+arr.size());
        
        System.out.println(arr.toString());
        int x=in.nextInt();
        for(int i=0;i<x;i++)
        {
        	System.out.println( arr.pop());
        }
        System.out.println( arr.peek()+","+arr.empty()+","+arr.size());
        System.out.println(arr.toString());
	}

}